﻿CREATE PROCEDURE [dbo].[StoreSwitch]
	@SensorId bigint,
	@Created datetimeoffset,	
  @EnergyBowPressed bit, 
  @Button tinyint,
  @ButtonState bit
AS
  begin transaction

  if not exists (select Id from Sensor where Id = @SensorId)
    begin
      insert Sensor (Id, Name) values (@SensorId, 'Unnamed')
    end 

  insert Switch(SensorId, Created, EnergyBowPressed, Button, ButtonState)
  values (@SensorId, @Created, @EnergyBowPressed, @Button, @ButtonState)
	
  commit